//
// Created by john on 2020/9/12.
//
#include <iostream>
#include <fstream>
#include <thread>
#include "sys/socket.h"
#include "arpa/inet.h"

#ifndef MYTEST_TSOCKET_H
#define MYTEST_TSOCKET_H

typedef  int (*eventAccept)(int,int);

//客户端信息
// ip 长度 端口 socketid
struct socket_client {
    int client_id;
    sockaddr_in sockaddr;
    socklen_t socklen;
};

class TSocket {
public:
    TSocket();
    void listen(int port);
    void start();
    ~TSocket();

public:
    int sock;


    void setOnAccept(eventAccept accept);

    eventAccept onRecv;
    eventAccept onSend;
    eventAccept onDisconnect;
private:
    eventAccept onAccept;
    void th_function(int sock_client);

};


#endif //MYTEST_TSOCKET_H
